package com.sky.controller.user;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.UserOrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "用户订单相关接口")
@AllArgsConstructor
public class UserOrderController {
    @Autowired
    private UserOrderService userOrderService;


    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("用户下单：{}", ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = userOrderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(int page,int pageSize,Integer status){
        PageResult pageResult = userOrderService.historyOrders(page,pageSize,status);
        return Result.success(pageResult);
    }

    @GetMapping("/reminder/{orderId}")
    public Result<String> reminder(@PathVariable Long orderId){
        userOrderService.reminder(orderId);
        return Result.success();
    }

    @GetMapping("/queryOrdersCheckStatus")
    public Result<PageResult> queryOrdersCheckStatus(int page,int pageSize,Integer status){
        PageResult pageResult = userOrderService.historyOrders(page,pageSize,status);
        return Result.success(pageResult);
    }

    @GetMapping("/orderDetail/{orderId}")
    public Result<OrderVO> orderDetail(@PathVariable Long orderId){
        OrderVO orderVO = userOrderService.orderDetail(orderId);
        return Result.success(orderVO);
    }

    @PostMapping("/cancel/{id}")
    @ApiOperation(value = "取消订单，修改订单状态")
    public Result<String> cancel(@PathVariable Long id){
        userOrderService.cancel(id);
        return Result.success();
    }

    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result<String> repetition(@PathVariable Long id){
        userOrderService.repetition(id);
        return Result.success();
    }
}
